package cm.unit2.theme4;

public class MinNumberInRotateArray {

	
	public int minNumberInRotateArray(int [] array) {
		int start = 0;
		int end = array.length - 1;
		int mid = array.length - 1;
//		System.out.println("start="+start+",mid="+mid+",end="+end+"\n");
		while (mid!=start) {
			mid = start + ((end-start)>>1);
			if (array[mid] > array[end]) {
				start = mid + 1;
			}else if (array[mid] < array[end]) {
				end = mid;
			}else {
				break;
			}
//			System.out.println("start="+start+",mid="+mid+",end="+end);
//			System.out.println("start>"+array[start]+",mid>"+array[mid]+",end="+array[end]);
		}
		
        return array[mid];
    }

	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int []arr = {3,4,5,1,2};
		MinNumberInRotateArray minNum = new MinNumberInRotateArray();
		System.out.println(minNum.minNumberInRotateArray(arr));;
	}

}
